//
//  ReserverInputView.swift
//  koolcar
//
//  Created by xiantian on 2023/11/29.
//

import UIKit

class ReserverInputView: UIView {
    var titleTxt: String? {
        didSet {
            let temp = String(format: "*%@", titleTxt ?? "")
            let attr = NSMutableAttributedString.init(string: temp)
            let attri = [NSMutableAttributedString.Key.foregroundColor: Theme.redColor]
            attr.addAttributes(attri, range: NSRange.init(location: 0, length: 1))
            self.titleLab.attributedText = attr
        }
    }
    private var titleLab: UILabel!
    var inputTFView: KInputTextField!
    var inputBtn: UIButton!

    override init(frame: CGRect) {
        super.init(frame: frame)
        titleLab = UILabel()
        titleLab.textColor = Theme.titleLabColor
        titleLab.backgroundColor = UIColor.clear
        titleLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        titleLab.numberOfLines = 1
        titleLab.lineBreakMode = .byTruncatingTail
        titleLab.textAlignment = .left
        self.addSubview(titleLab)
    
        inputTFView = KInputTextField()
        self.addSubview(inputTFView)
        
        inputBtn = UIButton()
        inputBtn.isHidden = true
        self.addSubview(inputBtn)
        
        self.addSnpLayout()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func addSnpLayout(){
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.top.equalTo(0)
            make.height.greaterThanOrEqualTo(20)
        }
        
        inputTFView.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.top.equalTo(titleLab.snp.bottom).offset(6)
            make.right.equalTo(0)
            make.height.greaterThanOrEqualTo(44)
            make.bottom.equalTo(0)
        }
        
        inputBtn.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.top.equalTo(titleLab.snp.bottom).offset(6)
            make.right.equalTo(0)
            make.height.greaterThanOrEqualTo(44)
        }
        self.layoutIfNeeded()
    }
}
